<template>
  <div class="user-profile-bg">
    <!-- 头部 -->
    <div class="user-profile-header">
      <van-icon name="arrow-left" class="user-profile-back" @click="goBack" />
      用户资料
    </div>

    <!-- 用户信息卡片 -->
    <div class="user-profile-card">
      <div class="user-profile-avatar-wrapper">
        <img class="user-profile-avatar" :src="userInfo.avatar" />
        <div class="user-profile-status" :class="userInfo.status === '在线' ? 'online' : 'offline'">
          {{ userInfo.status }}
        </div>
      </div>
      <div class="user-profile-info">
        <h2 class="user-profile-name">{{ userInfo.name }}</h2>
        <p class="user-profile-title">{{ userInfo.title }}</p>
        <p class="user-profile-department">{{ userInfo.department }}</p>
      </div>
    </div>

    <!-- 联系信息 -->
    <div class="user-profile-section">
      <div class="section-title">联系信息</div>
      <div class="contact-item" @click="copyEmail">
        <van-icon name="envelop-o" class="contact-icon" />
        <span class="contact-label">邮箱</span>
        <span class="contact-value">{{ userInfo.email }}</span>
        <van-icon name="copy-o" class="contact-action" />
      </div>
      <div class="contact-item" @click="copyPhone">
        <van-icon name="phone-o" class="contact-icon" />
        <span class="contact-label">电话</span>
        <span class="contact-value">{{ userInfo.phone }}</span>
        <van-icon name="copy-o" class="contact-action" />
      </div>
    </div>

    <!-- 操作按钮 -->
    <div class="user-profile-actions">
      <van-button 
        type="primary" 
        block 
        class="action-btn"
        @click="startChat"
      >
        <van-icon name="chat-o" />
        开始聊天
      </van-button>
      <van-button 
        type="default" 
        block 
        class="action-btn"
        @click="addContact"
      >
        <van-icon name="friends-o" />
        添加联系人
      </van-button>
    </div>
  </div>
</template>

<script>
import { Toast } from 'vant';

export default {
  name: 'UserProfile',
  data() {
    return {
      userInfo: {
        id: '',
        name: '',
        avatar: '',
        title: '软件工程师',
        department: '技术部',
        email: 'user@example.com',
        phone: '138****8888',
        status: '在线'
      }
    }
  },
  mounted() {
    this.initUserInfo();
  },
  methods: {
    initUserInfo() {
      // 从路由参数获取用户信息
      const { userId, userName, userAvatar } = this.$route.query;
      this.userInfo = {
        id: userId || '1',
        name: userName || '张三',
        avatar: userAvatar || 'https://img.yzcdn.cn/vant/cat.jpeg',
        title: '软件工程师',
        department: '技术部',
        email: 'user@example.com',
        phone: '138****8888',
        status: '在线'
      };
    },
    goBack() {
      this.$router.back();
    },
    copyEmail() {
      // 复制邮箱到剪贴板
      navigator.clipboard.writeText(this.userInfo.email).then(() => {
        Toast('邮箱已复制');
      });
    },
    copyPhone() {
      // 复制电话到剪贴板
      navigator.clipboard.writeText(this.userInfo.phone).then(() => {
        Toast('电话已复制');
      });
    },
    startChat() {
      // 跳转到聊天页面
      this.$router.push({
        path: '/chat',
        query: {
          userId: this.userInfo.id,
          userName: this.userInfo.name,
          userAvatar: this.userInfo.avatar
        }
      });
    },
    addContact() {
      Toast('已添加到联系人');
    }
  }
}
</script>

<style scoped>
.user-profile-bg {
  min-height: 100vh;
  background: #f5f5f5;
}

.user-profile-header {
   background: #1677ff;
  color: #fff;
  font-size: 22px;
  font-weight: bold;
  text-align: center;
  padding: 18px 0 12px 0;
  letter-spacing: 2px;
  position: relative;
}

.user-profile-back {
  position: absolute;
  left: 18px;
  top: 18px;
  font-size: 22px;
  color: #fff;
  cursor: pointer;
}

.user-profile-card {
  background: #fff;
  margin: 24px 16px;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  text-align: center;
}

.user-profile-avatar-wrapper {
  position: relative;
  display: inline-block;
  margin-bottom: 16px;
}

.user-profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 4px solid #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.user-profile-status {
  position: absolute;
  bottom: 0;
  right: 0;
  background: #52c41a;
  color: #fff;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  border: 2px solid #fff;
}

.user-profile-status.offline {
  background: #999;
}

.user-profile-name {
  font-size: 20px;
  font-weight: 600;
  color: #222;
  margin: 0 0 8px 0;
}

.user-profile-title {
  font-size: 14px;
  color: #666;
  margin: 0 0 4px 0;
}

.user-profile-department {
  font-size: 14px;
  color: #999;
  margin: 0;
}

.user-profile-section {
  background: #fff;
  margin: 16px;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: #222;
  margin-bottom: 16px;
}

.contact-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
}

.contact-item:last-child {
  border-bottom: none;
}

.contact-icon {
  font-size: 18px;
  color: #1677ff;
  margin-right: 12px;
}

.contact-label {
  font-size: 14px;
  color: #666;
  width: 60px;
}

.contact-value {
  flex: 1;
  font-size: 14px;
  color: #222;
  margin-left: 12px;
}

.contact-action {
  font-size: 16px;
  color: #999;
}

.user-profile-actions {
  margin: 24px 16px;
}

.action-btn {
  margin-bottom: 12px;
  border-radius: 12px;
  height: 48px;
  font-size: 16px;
  font-weight: 500;
}

.action-btn .van-icon {
  margin-right: 8px;
}
</style> 